﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using Project.Engine.Utilities;
using Project.Module.DAO.BL;
using Project.Module.DAO.CMSBL;
using Project.Engine.Control;
using Project.Module.Model;
using Project.Module.Model.CMS;

namespace Project.Module.View
{
    public class GioiThieuView : BasePageRazor
    {
        public NewsModel news = null;
        private NewsBL newsBl = new NewsBL();
        public List<ProductModel> listProductNew = null;
        public List<ProductModel> listProductHot = null;
        private ProductBL productBl = new ProductBL();
        private EventBL eventBl = new EventBL();
        public List<EventModel> listEvent = null;
        public string displayuser = String.Empty;

        protected override void InitializePage()
        {
            base.InitializePage();
            if (Session["username"] != null && ConvertUtil.ToString(Session["username"]).Length > 0)
            {
                displayuser = ConvertUtil.ToString(Session["username"]);
            }

            GetNew();
            GetListEvent();
            GetListProductNew();
            GetListProductHot();
        }

        private void GetNew()
        {
            this.news = newsBl.GetDetail();           
        }

        private void GetListProductNew()
        {
            this.listProductNew = productBl.GetListProductNew();
            if (this.listProductNew != null)
            {
                foreach (var item in this.listProductNew)
                {
                    item.url = StringUtil.UnicodeToKoDauUrl(StringUtil.ShortContent(item.Description, 5));
                    item.ImagePath = eventBl.GetImagePathById(item.ImageID);
                    item.title = StringUtil.ShortContent(item.Description, 5);
                    item.summary = StringUtil.ShortContent(item.Description, 20);
                    item.totalComment = (new FeedBackBL()).GetCommentProduct(item.ProductId, item.CatagoryId).ToList().Count;
                }
            }
        }

        private void GetListProductHot()
        {
            this.listProductHot = productBl.GetListProductHot();
            if (this.listProductHot != null)
            {
                foreach (var item in this.listProductHot)
                {
                    item.url = StringUtil.UnicodeToKoDauUrl(StringUtil.ShortContent(item.Description, 5));
                    item.ImagePath = eventBl.GetImagePathById(item.ImageID);
                    item.title = StringUtil.ShortContent(item.Description, 5);
                    item.summary = StringUtil.ShortContent(item.Description, 20);
                    item.totalComment = (new FeedBackBL()).GetCommentProduct(item.ProductId, item.CatagoryId).ToList().Count;
                }
            }
        }
        private void GetListEvent()
        {
            this.listEvent = eventBl.GetListEvent();
            if (this.listEvent != null)
            {
                foreach (var item in this.listEvent)
                {
                    item.url = StringUtil.UnicodeToKoDauUrl(StringUtil.ShortContent(item.Description, 5));
                    item.ImagePath = eventBl.GetImagePathById(item.ImageID);
                    item.title = StringUtil.ShortContent(item.Description, 5);
                    item.summary = StringUtil.ShortContent(item.Description, 20);
                    item.totalComment = (new FeedBackBL()).GetCommentEvent(item.EventID).ToList().Count;
                }
            }
        }
    }
}
